<template>
  <!-- vip定价 -->
  <div class="app-container">
    <el-button
      @click="addFn"
      type="primary"
      v-hasPermi="['financial:priceVip:add']"
      >新增</el-button
    >
    <div class="boxlaw">
      <h1>套餐定价</h1>
      <ComTable
        @handleStatusChange="changeStatusFn"
        @handleCurrentChange="CurrentPageChangeFn"
        @handleSizeChange="currentPageSizeChangeFn"
        :key="random"
        :list="tableList"
        :modes="tableModes"
        :config="{ border: true, loading }"
        :pagination="{ total: paging.total, pageNum: paging.pageNum }"
      >
        <el-table-column #default="{ row }" align="left">
          <template>
            <el-button
              v-hasPermi="['financial:priceVip:getInfo']"
              @click="editFn(row)"
              plain
              size="mini"
              type="primary"
              >修改</el-button
            >
          </template>
        </el-table-column>
      </ComTable>
      <AddAndEdit
        ref="AddAndEdit"
        @EventFretchList="getPriceVipListFn"
        :dialogVisible.sync="dialogVisible"
      ></AddAndEdit>
    </div>
  </div>
</template>

<script>
import ComForm from "../../../../components/comForm.vue";
import ComSelect from "../../../../components/comSelect.vue";
import ComTable from "../../../../components/comTable.vue";
import comForm from "../../../../components/comForm.vue";
// import { getdocGetTypeApi } from "@/wss/api/ContentSupervision.js";

import {
  getPriceVipListApi,
  getPriceVipEditApi,
} from "@/wss/api/financial/pricing/priceVip.js";
import AddAndEdit from "./addAndEdit.vue";
export default {
  name: "laws",
  dicts: ["sys_normal_disable"],
  components: { ComSelect, ComForm, comForm, ComTable, AddAndEdit },

  data() {
    return {
      // 是否显示对话框
      dialogVisible: false,
      initSelectValue: "",
      // 加载
      loading: false,
      paging: { pageNum: 1, pageSize: 10, status: "", total: 10 },
      // 切换筛选状态，不更新bug修复
      random: "",
      // 当前筛选的状态
      currentSelect: "",

      // 表格的数据
      tableList: [],
      tableModes: [
        {
          label: "套餐版本",
          mode: "version",
        },
        {
          showOverflowTooltip: true,

          width: 200,
          label: "原价（元）",
          mode: "amount",
          showOverflowTooltip: true,
        },
        {
          label: "销售价（元）",
          mode: "price",
        },
        {
          label: "问金（个）",
          mode: "voucher",
          showOverflowTooltip: true,
        },
        {
          label: "省（元）",
          mode: "save",
          showOverflowTooltip: true,
        },
        {
          label: "价格说明",
          mode: "info",
        },
        {
          label: "状态",
          mode: "status",
        },
      ],
    };
  },

  mounted() {
    this.getPriceVipListFn(this.paging);
  },
  methods: {
    // 改变函数状态
    async changeStatusFn(row) {
      let params = JSON.parse(JSON.stringify(row));
      params.id = params.idStr;
      console.log(params);
      let { code, msg } = await getPriceVipEditApi(params);
      // console.log(result);
      if (code == 200) {
        this.$modal.msgSuccess(msg);
        this.getPriceVipListFn();
      }
    },
    // 重设函数
    resetFn() {
      this.initSelectValue = "";
      this.romdom = Math.random();
      this.options.value = "";
      this.paging.status = "";
      console.log(this.paging, "重设");
    },
    // 当前页发生改变时候
    CurrentPageChangeFn(pageNUm) {
      this.paging.pageNum = pageNUm;
      this.getPriceVipListFn(this.paging);
    },
    // 页容量发生改变时候
    currentPageSizeChangeFn(pageSize) {
      this.paging.pageSize = pageSize;
      this.getPriceVipListFn(this.paging);
    },
    // 筛选数据
    queryFn(arr) {
      arr.forEach((item) => {
        for (const key in item) {
          this.paging[key] = item[key];
        }
      });
      this.currentSelect = this.initSelectValue;
      console.log(this.paging, "查询");
      this.paging.pageNum = 1;
      this.getPriceVipListFn(this.paging);
    },
    // 获取列表数据
    async getPriceVipListFn(pagination = null) {
      this.loading = true;
      let { rows, code } = await getPriceVipListApi(pagination);
      if (code == 200) {
        this.tableList = rows;
        this.tableList.map((item) => {
          item.save = item.amount - item.price;
        });
      }
      this.loading = false;
      console.log(rows, "vip数据");
    },
    // 打开新增对话框
    addFn() {
      this.dialogVisible = true;
    },
    // 打开查看对话框
    async editFn(row) {
      //根据id获取详细信息
      await this.$refs.AddAndEdit.getPriceVipGetInfoFn(row);
      // console.log(result);
      this.dialogVisible = true;
    },
  },
};
</script>

<style lang ="scss" scoped>
.comform {
  margin-top: 20px;
}
</style>